/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaDefinicionGrilla.java
 *
 * Created on Apr 23, 2009, 8:18:41 PM
 */

package geomain;

import java.beans.PropertyVetoException;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import modelo.Punto;

/**
 *
 * @author Diego Anzola, Fredy Bello
 */
public class VentanaDefinicionGrilla extends javax.swing.JInternalFrame {

    private Main ventanaPadre = null;

    /** Creates new form VentanaDefinicionGrilla */
    public VentanaDefinicionGrilla() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSpinnerColumnas = new javax.swing.JSpinner();
        jSpinnerFilas = new javax.swing.JSpinner();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();

        setClosable(true);
        setResizable(true);
        setTitle("Grilla");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Parámetros"));

        jLabel1.setText("Columnas");

        jSpinnerColumnas.setModel(new javax.swing.SpinnerNumberModel(10, 5, 50, 1));

        jSpinnerFilas.setModel(new javax.swing.SpinnerNumberModel(10, 5, 50, 1));

        jButton1.setText("Aceptar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Filas");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSpinnerFilas, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                            .addComponent(jSpinnerColumnas, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jSpinnerColumnas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jSpinnerFilas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        if(this.getVentanaPadre()==null){
            // Una referencia a la ventana Principal de la aplicacion
            this.setVentanaPadre((geomain.Main) this.getParent().getParent().getParent().getParent().getParent());
        }
        
        jSpinnerColumnas.setValue(ventanaPadre.getEvaluacionDominio().getDominioInicial().getGrillaDominio().getColumnas());
        jSpinnerFilas.setValue(ventanaPadre.getEvaluacionDominio().getDominioInicial().getGrillaDominio().getFilas());

    }//GEN-LAST:event_formInternalFrameOpened

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            ventanaPadre.getEvaluacionDominio().getDominioInicial().getGrillaDominio().setColumnas(Integer.parseInt(jSpinnerColumnas.getValue().toString()));
            ventanaPadre.getEvaluacionDominio().getDominioInicial().getGrillaDominio().setFilas(Integer.parseInt(jSpinnerFilas.getValue().toString()));
            ventanaPadre.getEvaluacionDominio().getDominioInicial().setConjuntoP(new HashSet());
            ventanaPadre.getEvaluacionDominio().getDominioInicial().setConjuntoS(new HashSet());

            ventanaPadre.getEvaluacionDominio().getDominioEvaluado().setConjuntoP(new HashSet());
            ventanaPadre.getEvaluacionDominio().getDominioEvaluado().setConjuntoS(new HashSet());
            ventanaPadre.getEvaluacionDominio().getDominioEvaluado().getGrillaDominio().setPuntoOrigen(new Punto(0, 0));

            if((ventanaPadre.getMiVentanaVisualizacion()!=null)&&(!ventanaPadre.getMiVentanaVisualizacion().isClosed())){
                ventanaPadre.getMiVentanaVisualizacion().dibujarDominio();
            }
            this.setClosed(true);
        } catch (Exception ex) {
            Logger.getLogger(VentanaDefinicionGrilla.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSpinner jSpinnerColumnas;
    private javax.swing.JSpinner jSpinnerFilas;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the ventanaPadre
     */
    public Main getVentanaPadre() {
        return ventanaPadre;
    }

    /**
     * @param ventanaPadre the ventanaPadre to set
     */
    public void setVentanaPadre(Main ventanaPadre) {
        this.ventanaPadre = ventanaPadre;
    }

}
